<template>
  <!-- 添加或修改驾驶员信息对话框 -->
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="1000px"
    append-to-body
    :close-on-click-modal="false"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="98px" label-position="right" class="flex-form"
             size="small">
      <el-form-item label="姓名" prop="name">
        <el-input v-model.trim="form.name" placeholder="请输入姓名"/>
      </el-form-item>

      <el-form-item label="手机号" prop="phone">
        <el-input v-model.trim="form.phone" placeholder="请输入手机号"/>
      </el-form-item>

      <el-form-item label="准驾车型" prop="permittedVehicleTypeName">
<!--        <el-input v-model.trim="form.permittedVehicleTypeName" placeholder="请输入准驾车型"/>-->
        <el-select v-model.trim="form.permittedVehicleTypeName" placeholder="请选择准驾车型">
          <el-option
            v-for="dict in dict.type.quasi_driving_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="道路运输从业资格证号" prop="roadTransportQualificationCertificateNum">
        <el-input v-model.trim="form.roadTransportQualificationCertificateNum"
                  placeholder="请输入道路运输从业资格证号"/>
      </el-form-item>

      <el-form-item label="从业资格证开始时间" prop="roadTransportQualificationCertificateStartTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.roadTransportQualificationCertificateStartTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择从业资格证开始时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="从业资格证结束时间" prop="roadTransportQualificationCertificateEndTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.roadTransportQualificationCertificateEndTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择从业资格证结束时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="驾照有效期开始时间" prop="driverLicenseStartTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.driverLicenseStartTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择驾照有效期开始时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="驾照有效期结束时间" prop="driverLicenseEndTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.driverLicenseEndTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择驾照有效期结束时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="身份证号" prop="idCardNum">
        <el-input v-model.trim="form.idCardNum" placeholder="请输入身份证号"/>
      </el-form-item>

      <el-form-item label="身份证有效期开始时间" prop="idCardStartTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.idCardStartTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择身份证有效期开始时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="身份证有效期结束时间" prop="idCardEndTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.idCardEndTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择身份证有效期结束时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="驾照号" prop="driverLicenseNum">
        <el-input v-model.trim="form.driverLicenseNum" placeholder="请输入驾照号"/>
      </el-form-item>

      <el-form-item label="驾照正页">
        <imageUpload v-model.trim="form.driverLicenseUrl" :limit="1"/>
      </el-form-item>

      <el-form-item label="驾照副页">
        <imageUpload v-model.trim="form.driverLicenseCopyUrl" :limit="1"/>
      </el-form-item>

      <el-form-item label="道路运输从业资格证照片" prop="roadTransportQualificationCertificateUrl">
        <imageUpload v-model.trim="form.roadTransportQualificationCertificateUrl" :limit="1"/>
      </el-form-item>

<!--      <el-form-item label="审核时间" prop="checkTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.checkTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择审核时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="审核人" prop="checkUserId">
        <el-input v-model.trim="form.checkUserId" placeholder="请输入审核人"/>
      </el-form-item>

      <el-form-item label="审核备注" prop="checkRemark">
        <el-input v-model.trim="form.checkRemark" type="textarea" placeholder="请输入内容"/>
      </el-form-item>-->

      <el-form-item label="身份证正面">
        <imageUpload v-model.trim="form.certificateFront" :limit="1"/>
      </el-form-item>

      <el-form-item label="身份证背面">
        <imageUpload v-model.trim="form.certificateBehind" :limit="1"/>
      </el-form-item>

<!--      <el-form-item label="关联企业" prop="enterpriseId">
        <el-input v-model.trim="form.enterpriseId" placeholder="请输入关联企业"/>
      </el-form-item>-->

<!--      <el-form-item label="同步状态" prop="syncStatus">
        <el-select v-model.trim="form.syncStatus" placeholder="请选择同步状态">
          <el-option
            v-for="dict in dict.type.sync_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>-->

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {getYjDriverInfo, addYjDriverInfo, updateYjDriverInfo} from "@/api/miniapp/yjDriverInfo";

export default {
  name: "YjDriverInfo-addEdit",
  props: {
    dialogType: {
      type: String,
      default: "add",
    },
    rowData: {
      type: Object,
      default: () => {
      },
    },
    dict: {}
  },
  data() {
    return {
      // 弹出层
      dialogVisible: false,
      // 标题
      title: "新增",
      // 表单参数
      form: {
        id: null,
        name: null,
        phone: null,
        permittedVehicleTypeName: null,
        roadTransportQualificationCertificateNum: null,
        roadTransportQualificationCertificateStartTime: null,
        roadTransportQualificationCertificateEndTime: null,
        driverLicenseStartTime: null,
        driverLicenseEndTime: null,
        idCardNum: null,
        idCardStartTime: null,
        idCardEndTime: null,
        driverLicenseNum: null,
        driverLicenseUrl: null,
        driverLicenseCopyUrl: null,
        roadTransportQualificationCertificateUrl: null,
        checkTime: null,
        checkUserId: null,
        checkRemark: null,
        certificateFront: null,
        certificateBehind: null,
        enterpriseId: null,
        syncStatus: null,
        syncBy: null,
        syncTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null

      },
      // 驾驶员信息表格数据
      yjDriverInfoList: [],
      // 表单校验
      rules: {
        name: [
          {required: true, message: "姓名不能为空", trigger: "blur"}
        ],
        phone: [
          {required: true, message: "手机号不能为空", trigger: "blur"}
        ],
        permittedVehicleTypeName: [
          {required: true, message: "准驾车型不能为空", trigger: "blur"}
        ],
        roadTransportQualificationCertificateNum: [
          {required: true, message: "道路运输从业资格证号不能为空", trigger: "blur"}
        ],
        roadTransportQualificationCertificateStartTime: [
          {required: true, message: "从业资格证开始时间不能为空", trigger: "blur"}
        ],
        roadTransportQualificationCertificateEndTime: [
          {required: true, message: "从业资格证结束时间不能为空", trigger: "blur"}
        ],
        driverLicenseStartTime: [
          {required: true, message: "驾照有效期开始时间不能为空", trigger: "blur"}
        ],
        driverLicenseEndTime: [
          {required: true, message: "驾照有效期结束时间不能为空", trigger: "blur"}
        ],
        idCardNum: [
          {required: true, message: "身份证号不能为空", trigger: "blur"}
        ],
        driverLicenseNum: [
          {required: true, message: "驾照号不能为空", trigger: "blur"}
        ],
      }
    };
  },
  methods: {
    open() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        if (this.dialogType == "add") {
          this.title = "新增";
        } else if (this.dialogType == "edit") {
          this.title = "编辑";
          this.loadDetail();
        } else if (this.dialogType == "detail") {
          this.title = "详情";
          this.loadDetail();
        }
      });
    },
    close() {
      this.$refs["form"].resetFields();
      this.dialogVisible = false;
    },

    // 获取详情
    loadDetail() {
      const id = this.rowData.id;
      getYjDriverInfo(id).then((res) => {
        if (res.code == 200) {
          this.form = res.data;
        }
      });
    },

    // 提交表单
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let params = {
            ...this.form,
          };
          if (this.dialogType == "add") {
            addYjDriverInfo(this.form).then(res => {
              if (res.code === 200) {
                this.$modal.msgSuccess("新增成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          } else {
            params.id = this.rowData.id;
            updateYjDriverInfo(this.form).then(res => {
              if (res.code === 200) {
                this.$modal.msgSuccess("修改成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
